package com.gitee.jktantan.datasource.monitor.servlet;

import com.gitee.jktantan.datasource.monitor.analyze.metrics.MetricsCollector;
import com.gitee.jktantan.datasource.monitor.analyze.metrics.StatisticsEntity;
import com.gitee.jktantan.datasource.monitor.analyze.p6spy.QueryCollector;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/dsmonitor")
public class StatisticsOutputController {

    @Resource
    private MetricsCollector metricsCollector;

    @Resource
    private QueryCollector queryCollector;

    @RequestMapping("/querystats")
    public Object p6spyStatistics(@RequestParam("id") String id) {
        return queryCollector.getStatistics(id);
    }

    @RequestMapping("/queryds")
    public Set p6spyDataSources() {
        return queryCollector.getDataSourceSet();
    }

    @RequestMapping("/dsstats")
    public List<StatisticsEntity> metricsStatistics() {
        return metricsCollector.getStatistics();
    }
}
